import $V from './$V';

export default function vhf(price, length) {
    let vhfValue = $V.init(price.length,0.5);
    let diffOfPrice = $V.init(price.length,0);
    diffOfPrice = $V.copy_by_index(diffOfPrice,1,$V.sub($V.subv(price,1,price.length),$V.subv(price,0,price.length-1)));
    diffOfPrice = $V.abs(diffOfPrice);
    for(let i = length - 1;i < price.length;i++){
        vhfValue[i] = Math.abs($V.max($V.subv(price,i-length+1,i+1))-$V.min($V.subv(price,i-length+1,i+1)))/$V.sum($V.subv(diffOfPrice,i-length+1,i+1));
    }
    return vhfValue;
}
